package com.maxlen.ware.controller;

import com.maxlen.common.utils.PageUtils;
import com.maxlen.common.utils.R;
import com.maxlen.common.vo.PageParamsVO;
import com.maxlen.ware.entity.PurchaseEntity;
import com.maxlen.ware.entity.WareInfoEntity;
import com.maxlen.ware.entity.vo.PurchaseDoneVO;
import com.maxlen.ware.entity.vo.PurchaseMergeVO;
import com.maxlen.ware.service.PurchaseService;
import com.maxlen.ware.service.WareInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 采购单
 *
 * @author MaxLen
 * @email MaxLen@gmail.com
 * @date 2022-10-27 11:02:35
 */
@RestController
@RequestMapping("ware/purchase")
public class PurchaseController {
    @Autowired
    private PurchaseService purchaseService;

    /**
     * 采购完成
     */
    @PostMapping("/done")
    public R finish(@RequestBody PurchaseDoneVO purchaseDoneVO){
        purchaseService.finish(purchaseDoneVO);
        return R.ok();
    }

    /**
     * 领取采购单
     */
    @PostMapping("/received")
    public R received(@RequestBody List<Long> ids){
        purchaseService.received(ids);
        return R.ok();
    }

    /**
     * 合并采购需求
     */
    @PostMapping("/merge")
    public R merge(@RequestBody PurchaseMergeVO purchaseMergeVO){
        purchaseService.mergePurchase(purchaseMergeVO);
        return R.ok();
    }

    /**
     * 查询没有被领取的采购单
     */
    @PostMapping("/unreceive/list")
    public R unReceive(@RequestBody PageParamsVO params){
        PageUtils page = purchaseService.getUnReceive(params);
        return R.ok().put("page", page);
    }

    /**
     * 列表
     */
    @PostMapping("/list")
    // @RequiresPermissions("ware:wareinfo:list")
    public R list(@RequestBody PageParamsVO params){
        PageUtils page = purchaseService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    // @RequiresPermissions("ware:wareinfo:info")
    public R info(@PathVariable("id") Long id){
        PurchaseEntity wareInfo = purchaseService.getById(id);

        return R.ok().put("wareInfo", wareInfo);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    // @RequiresPermissions("ware:wareinfo:save")
    public R save(@RequestBody PurchaseEntity purchase){
        purchaseService.save(purchase);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    // @RequiresPermissions("ware:wareinfo:update")
    public R update(@RequestBody PurchaseEntity purchase){
        purchaseService.updateById(purchase);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    // @RequiresPermissions("ware:wareinfo:delete")
    public R delete(@RequestBody Long[] ids){
        purchaseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
